home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Complet / emovix / eMovix-0.9.0pre1_Setup.exe / {app} / src / movix / movix.pl < prev    next >
Encoding:
Perl Script  |  2003-12-26  |  35.0 KB  |  1,043 lines

  1. #!/usr/bin/perl
  2.  
  3. ### get the name used to call this script...
  4. $0 =~ /\/(\w+)$/;
  5. $scriptName = $1;
  6. ### there can be an argument: the dvd or vcd chapter
  7. $N = $ARGV[0];
  8.  
  9. $modLog = "/tmp/modprobe.log";
  10. $modErr = "/tmp/modprobe.err";
  11. $cdMntLog = "/tmp/cdMount.log";
  12. $cdMntErr = "/tmp/cdMount.err";
  13.  
  14. ########################################
  15. ### Getting rid of the junk on the screen
  16. ###############
  17. # we don't want kernel msgs on-screen...
  18. `echo "3 4 1 7" > /proc/sys/kernel/printk`;
  19. system "clear";
  20.  
  21. ### This is needed because for some strange bug only the first two user boot args
  22. ### are actually exported as env variables
  23. loadBootParm();
  24. readRCFile();
  25.  
  26. $shut = $RC{'shut'};
  27. $shut = $ENV{'SHUT'} if exists $ENV{'SHUT'};
  28. $random = $RC{'random'};
  29. $random = $ENV{'RANDOM'} if exists $ENV{'RANDOM'};
  30. $loop = $RC{'loop'};
  31. $loop = $ENV{'LOOP'} if exists $ENV{'LOOP'};
  32. $loop = 1 unless $loop =~ /^\d+$/;
  33. $eject = $RC{'eject'};
  34. $eject = $ENV{'EJECT'} if exists $ENV{'EJECT'};
  35. $reboot = $RC{'reboot'};
  36. $reboot = $ENV{'REBOOT'} if exists $ENV{'REBOOT'};
  37. $dma = $RC{'dma'};
  38. $dma = $ENV{'DMA'} if exists $ENV{'DMA'};
  39. $slow = $RC{'slow'};
  40. $slow = $ENV{'SLOW'} if exists $ENV{'SLOW'};
  41. $region = $RC{'region'};
  42. $region = $ENV{'REGION'} if exists $ENV{'REGION'};
  43. $dxr3 = $RC{'dxr3'};
  44. $dxr3 = $ENV{'DXR3'} if exists $ENV{'DXR3'};
  45.  
  46. ##########################################################
  47. ### Making sure no other movix.pl process is running...
  48. #######
  49. #my @ids;
  50. #foreach (`ps auxw`){
  51. ##  print "$_\n";
  52. #  push @ids, $1 if /^\w+\s+(\d+)\s+.+(movix.pl|mplayer)/;
  53. #}
  54. ##print "ids = @ids\n";
  55. ##print "pr = $$";
  56. #foreach (@ids){
  57. #  `kill -9 $_` unless $_ == $$;
  58. #>}
  59.  
  60. foreach (split " ", `ls /dev/cdroms/cdrom*`){
  61.   /(\d+)$/;
  62.   `mkdir -p /cdrom$1`;
  63.   `mount -t supermount -o fs=iso9660:udf:vfat,dev=/dev/cdroms/cdrom$1,--,ro none /cdrom$1 >> $cdMntLog 2>> $cdMntErr`
  64.     unless `grep cdrom$1 /etc/mtab` =~ /cdrom$i/;
  65. }
  66.  
  67. ########################################
  68. ### Mounting the right CD on /cdrom...
  69. ###############
  70. $dvd_device = "";
  71. $cdrom_device = "";
  72. `rm -f /tmp/movix.list`;
  73. cdDetect($scriptName,$N);
  74.  
  75. system "echo \"The movie will start in a few seconds...\"";
  76. #sleep(2) unless $scriptName eq "dvd";
  77.  
  78. ########################################
  79. ### Building the mplayer options
  80. ###############
  81.  
  82. ########################################
  83. ### Checking for an AGP card...
  84. ###############
  85. open(PCI,"/proc/pci");
  86. while(<PCI>){
  87.     next unless /^\s*Bus  1/;
  88.     $bus = "AGP";
  89.     last;
  90. }
  91. close PCI;
  92. $bus = "PCI" unless $bus eq "AGP";
  93.  
  94. ########################################
  95. ### Identifying your video card
  96. ###############
  97. open(PCI,"/proc/pci");
  98. while(<PCI>){
  99.     if( $bus eq "PCI" ){
  100.     next unless /^\s*VGA compatible controller\:/;
  101.     $videoCardLine = $_;
  102.     last;
  103.     } else {
  104.     next unless /^\s*Bus  1/;
  105.     $videoCardLine = <PCI>;
  106.     last;
  107.     }
  108. }
  109. close(PCI);
  110. if( $videoCardLine !~ /^\s*VGA compatible controller\:/ ){
  111.     print "I can't find any video card entry in your /proc/pci file, this is extremely odd!\n";
  112.     print "Most likely the movie won't manage to start...\n";
  113. }
  114.  
  115. #######################################
  116. ### Checking for a Dx3/H+ card...
  117. ###############
  118. open(PCI,"/proc/pci");
  119. while(<PCI>){
  120.     next unless /^\s*Multimedia controller/;
  121.     $videoCardLine = "DXR3/H+" if /REALmagic Hollywood Plus|dxr3/i and $dxr3 !~ /^n/i;
  122.     last;
  123. }
  124. close PCI;
  125.  
  126. ######
  127. ##  Just spotting "special" video cards for setting later special options
  128. ####
  129. $videoCard = "NVidia"     if $videoCardLine =~ /geforce/i;
  130. $videoCard = "3Dfx"       if $videoCardLine =~ /voodoo/i;
  131. $videoCard = "Savage"     if $videoCardLine =~ /savage/i;
  132. $videoCard = "Ati"        if $videoCardLine =~ /ATI Technologies/i;
  133. $videoCard = "DXR3/H+"    if $videoCardLine eq "DXR3/H+";
  134. $videoCard = "Matrox"     if $videoCardLine =~ /Matrox.+ G[245][05]0/i;
  135. $videoCard = "CyberBlade" if $videoCardLine =~ /CyberBlade/i;
  136.  
  137. ########################################
  138. ### Evaluating your CPU speed
  139. ###############
  140. open(CPUINFO,"/proc/cpuinfo");
  141. while(<CPUINFO>){
  142.     if( /^cpu MHz\s*\:\s*(\d+)/ ){
  143.     $mhz = $1;
  144.     }
  145. }
  146. close CPUINFO;
  147. ###################
  148. ## We are going to compare this value with a fixed $MHZ value
  149. ## in order to enable sw accel. if the CPU is fast enough and
  150. ## the card is not natively accelerated by mplayer.
  151. ##################
  152. ### Thanks to Eivind Kjorstad for his nice suggestion about framefrop!
  153. $fMHZ  = 290;  ## few MHZ
  154. $vfMHZ = 200;  ## very few MHZ!
  155.  
  156. ########################################
  157. ### Evaluating the best options for your video card
  158. ### The idea is:
  159. ### 1. default label     - try to get the best options trying to set
  160. ###                        fullscreen play when it seems reasonable
  161. ### 2. vesa & FB labels  - do not even try to resize the screen by hw or sw means.
  162. ###                        It is intended only as last hope for machines on which
  163. ###                        the default does not work.#
  164. ##############
  165. ## Apparently the "vesa" driver works much better *without* the "-fs" option
  166. ## so now are it makes more sense to add it when needed than taking it off!
  167. #$options = "-quiet -fs ";
  168. $options = "-quiet -framedrop ";
  169. ### -vop eq activates software brightness/contrast controls
  170. $vop = "eq";
  171.  
  172. ## apparently there are cards that do not work if we explicitly use "-ao alsa9"!
  173. #$aodriver = "alsa9";
  174.  
  175. # If the AUDIO variable is set to an integer, ALSA is explicitly selected and
  176. # set to the selected hardware
  177. if ($ENV{"AUDIO"} =~ /^\d+$/) {
  178.     $aodriver = "alsa9:hw:" . $ENV{"AUDIO"} . ",0";
  179. }
  180.  
  181. ########################################
  182. ### In case use of the "vesa" driver is forced...
  183. ###############
  184. if( $ENV{"LABEL"} eq "vesa" ){
  185.   $vodriver   = "vesa";
  186.   if( $videoCardLine =~ /Radeon|Mach64| Rage |G200|G400|G450|G550|CyberBlade/i and $ENV{"ACCEL"} !~ /sw|no/ ){
  187.     $vodriver .= ":vidix";
  188.     $options  .= "-fs -zoom ";
  189.   } elsif( ( $mhz > $fMHZ and $ENV{"ACCEL"} ne "no" ) or $ENV{"ACCEL"} eq "sw" ) {
  190.     $vop .= ",expand=800:600";
  191.     $vop .= ",scale=800:-2";
  192.   } else {
  193. #    $options .= "-framedrop ";
  194.     $options  .= "-fs -zoom ";
  195.     $options =~ s/ -framedrop / -hardframedrop /
  196.       if $mhz < $vfMHZ;
  197.   }
  198.   ########################################
  199.   ### In case use of the "aa" driver is forced...
  200.   ###############
  201. } elsif( $ENV{"LABEL"} eq "aa" ){
  202.   $vodriver   = "aa";
  203.   $options   .= "-aabold -aadim -aadriver linux -aafloyd_steinberg -aadimmul 1.71 -aaboldmul 1.43 -aacontrast 30 -really-quiet ";
  204.   system "setfont /usr/share/kbd/consolefonts/lat1-08.psfu.gz";
  205.   #    if( $ENV{'FBRES'} =~ /^(\d+)x(\d+)$/ ){
  206.   #      system "fbset -xres $1 -yres $2";
  207.   #    }
  208.   ########################################
  209.   ### In case use of the sdl driver is forced...
  210.   ###############
  211. } elsif( $ENV{"LABEL"} eq "sdl" ){
  212.   unless( -e "/dev/fb0" ){
  213.     system "echo \"No FrameBuffer device has been detected, the sdl driver can't run without it :-(\"";
  214.     system "echo \"Please reboot and select a different driver\"";
  215.     reboot(5);
  216.   }
  217.   $vodriver = "sdl";
  218.   $xSize    = getFBxSize();
  219.   if( $mhz > $fMHZ ) {
  220.     $vop .= ",scale=$xSize:-2";
  221.     ## Can't understand why but there is A-V sync loss even though in my PC the same options work fine
  222.     ## so until I'll find a solution it is good to add a framedrop to keep audio & video on sync
  223. #    $options .= "-framedrop ";
  224.   }
  225.   system "ln -s /dev/misc/psaux /dev/mouse";
  226.   ########################################
  227.   ### In case use of the vesa generic FrameBuffer driver is forced...
  228.   ###############
  229. } elsif( $ENV{"LABEL"} eq "vesaFB" ) {
  230.   $vodriver = "fbdev";
  231.   $xSize    = getFBxSize();
  232.   $ySize    = getFBySize();
  233.   $options .= "-geometry 50%:50% ";
  234.   if( $videoCardLine =~ /Radeon|Mach64| Rage |G200|G400|G450|G550|CyberBlade/i and $ENV{"ACCEL"} !~ /sw|no/ ){
  235.     ### Warning: -fs w/fbdev driver crashes MPlayer if the video rez
  236.     ### is bigger than the screen rez.
  237.     ### But if we don't add "-fs" then the movie won't be resized anymore.
  238.     ### Someone should fix this bug eventually...
  239.     $vodriver .= ":vidix";
  240.     $options .= "-fs ";
  241.   } elsif( ( $mhz > $fMHZ and $ENV{"ACCEL"} ne "no" ) or $ENV{"ACCEL"} eq "sw" ) {
  242.     $vop .= ",expand=$xSize:$ySize";
  243.     $vop .= ",scale=$xSize:-2";
  244.   } else {
  245. #    $options .= "-framedrop ";
  246.     $options =~ s/ -framedrop / -hardframedrop /
  247.       if $mhz < $vfMHZ;
  248.   }
  249.   ########################################
  250.   ### In case use of the FrameBuffer specific card driver is forced...
  251.   ###############
  252. } elsif( $ENV{"LABEL"} eq "FB" ) {
  253.   unless( -e "/dev/fb0" ){
  254.     system "echo \"No FrameBuffer device has been detected, the fbdev driver can't run without it :-(\"";
  255.     system "echo \"Please reboot and select a different driver\"";
  256.     system "echo \"(press F2 at the boot prompt for a complete list)\"";
  257.     reboot(5);
  258.   }
  259.   $vodriver = "fbdev";
  260.   $vodriver = "tdfxfb" if $videoCard eq "3Dfx";
  261.   $xSize = 800;
  262.   $ySize = 600;
  263.   $options .= "-geometry 50%:50% ";
  264.   if( $videoCardLine =~ /Radeon|Mach64| Rage |G200|G400|G450|G550|CyberBlade/i and $ENV{"ACCEL"} !~ /sw|no/ ){
  265.     ### Warning: -fs w/fbdev driver crashes MPlayer if the video rez
  266.     ### is bigger than the screen rez.
  267.     ### But if we don't add "-fs" then the movie won't be resized anymore.
  268.     ### Someone should fix this bug eventually...
  269.     $vodriver .= ":vidix";
  270.     $options .= "-fs ";
  271.   } elsif( ( $mhz > $fMHZ and $ENV{"ACCEL"} ne "no" ) or $ENV{"ACCEL"} eq "sw" ) {
  272.     $vop .= ",expand=$xSize:$ySize";
  273.     $vop .= ",scale=$xSize:-2";
  274.   } else {
  275. #    $options .= "-framedrop ";
  276.     $options =~ s/ -framedrop / -hardframedrop /
  277.       if $mhz < $vfMHZ;
  278.   }
  279.   ## Setting the right parameters for the FB...
  280.   ## btw, it's set to 16bpp since my radeon do not go higher than that :-)
  281.   ## maybe a parameter may be introduce to allow users choose their own
  282.   ## (or maybe a menu?)
  283.   system "fbset -t 17762 152 32 27 1 64 3 -g $xSize $ySize $xSize $ySize 16 -hsync high -vsync high";
  284. #  system "fbset -depth 32 -xres $xSize -yres $ySize";
  285. #  system "fbset -depth 24 -xres 640 -yres 480";
  286.   #######################################
  287.   ###  In case we need to use TV-out
  288.   ###  we may have to run a few utilities...
  289.   ###  Thanks a lot to Balazs Barany and Nico Berndt for providing the commands
  290.   ###  I'm using below!
  291.   ################################
  292. } elsif( $ENV{"LABEL"} eq "TV" ) {
  293.  
  294.   # Should the framebuffer be set to 32 colors later? 
  295.   # This will later be set to false if necessary.
  296.   $canChangeFB = true;
  297.  
  298.   if ($videoCard eq "Savage") {
  299.     # Trying to select the appropriated region code.
  300.     if ( defined $region ) {
  301.       if ( $region =~ /ntsc-j/i ) {
  302.         $region = "NTSCJ";
  303.       } elsif ( $region =~ /ntsc/i ) {
  304.         $region = "NTSC";
  305.       } elsif ( $region =~ /pal/i ) {
  306.         $region = "PAL";
  307.       }
  308.       system "s3switch tv $region >> /tmp/s3switch.log 2>> /tmp/s3switch.err";
  309.     } else {
  310.       # Use the default region setting of the chip. Also, on some systems,
  311.       # s3switch segfaults if any of the REGIONs is set.
  312.       system "s3switch tv >> /tmp/s3switch.log 2>> /tmp/s3switch.err";
  313.     }
  314.     $vodriver = "vesa";
  315.     $options .= "-fs ";
  316.  
  317.   } elsif( $videoCard eq "NVidia" ) {
  318.  
  319.     my ( $xrez, $yrez ) = ( 768, 576 );
  320.  
  321.     ( $xrez, $yrez ) = ( 800, 600 )
  322.       if defined $region and $region =~ /ntsc/i;
  323.  
  324.     # switch into the full TV resolution, this works for PAL
  325.     system "fbset -t 20203 40 0 63 29 56 4 -g $xrez $yrez $xrez $yrez 32 -bcast true -a"
  326.       if $region =~ /pal/i;
  327.  
  328.     my $nvtv = "nvtv -r $xrez,$yrez -s Large --set flicker:25 -t";
  329.     $nvtv .= " -S $region" if  defined $region;
  330.     system "$nvtv";
  331.  
  332.     $vodriver = "fbdev";
  333.     $vop .= ",scale=$xrez:-2";
  334.  
  335.   } elsif ($videoCard eq "Matrox") {
  336.     
  337.     # This is model dependent. Feedback to balazs@tud.at
  338.     if ($videoCardLine =~ /Matrox.+G[45]50/i ) {
  339.       # G450, G550: info from http://www.bglug.ca/matrox_tvout/
  340.       # set up the output
  341.       system "modprobe matroxfb_crtc2";
  342.       system "matroxset -f /dev/fb0 -m 5";
  343.       system "matroxset -f /dev/fb1 -m 2";
  344.       $fb = 'fb1';
  345.       # switch to the full TV resolution (This is PAL. NTSC, anyone?)
  346.       system "fbset -fb /dev/$fb -xres 768 -yres 576 -depth 32 -upper 44 -lower 4 -vslen 1";
  347.     } elsif ($videoCardLine =~ /Matrox.+G400/i ) {
  348.     # G400: info from http://www.netnode.de/howto/matrox-fb.html
  349.       # loading modules takes time
  350.       system "echo \"or more...\"";
  351.       system "modprobe matroxfb_crtc2";
  352.       system "modprobe -s mga_vid        >> $modLog 2>> $modErr";
  353.       system "modprobe -s matroxfb_maven >> $modLog 2>> $modErr";
  354.       system "modprobe -s i2c-matroxfb   >> $modLog 2>> $modErr";
  355.       # set up the output
  356.       system "matroxset -f /dev/fb1 -m 0";
  357.       system "matroxset -f /dev/fb0 -m 3";
  358.       $fb = 'fb1';
  359.       $vodriver = 'mga';
  360.       $options .= "-fs ";
  361.       # switch into the full TV resolution, this works for PAL
  362.       system "fbset -g 768 576 768 576 32 -t 20203 40 0 63 29 56 4 -bcast true";
  363.       # change contrast and saturation of G400 TV-out by setting hardware registers
  364.       # hue is reg 0x25, brightness is reg 0x0e
  365.       system "matrox 0x1e 0xb0 > /dev/null 2> /dev/null";
  366.       system "matrox 0x20 0xcc > /dev/null 2> /dev/null";
  367.       system "matrox 0x22 0xcc > /dev/null 2> /dev/null";
  368.     } elsif ($videoCardLine =~ /Matrox.+G200/i ) {
  369.       # G200: info from http://marvel.sourceforge.net/
  370.       # set up the output
  371.       system "matroxset -f /dev/fb0 -m 3";
  372.       $fb = 'fb0';
  373.       # switch to the full TV resolution (this is PAL. NTSC, anyone?)
  374.       system "fbset -g 768 576 768 576 32 -t 20203 40 0 63 29 56 4 -bcast true";
  375.     }
  376.  
  377.     # Trying to select the appropriate region code,
  378.     # "-o 1 1" is for PAL, "-o 1 2" for NTSC.
  379.     if ( defined $region ) {
  380.       if ( $region =~ /ntsc/i ) {
  381.     # Needs testing, if someone has this plz contact Pascal Giard.
  382.         $region = "2";
  383.       } elsif ( $region =~ /pal/i ) {
  384.         $region = "1";
  385.       }
  386.       system "matroxset -f /dev/$fb -o 1 $region";
  387.     } else {
  388.       system "matroxset -f /dev/$fb -o 1 1";
  389.     }
  390.     
  391.     if ($videoCardLine !~ /Matrox.+G400/i ) {
  392.       # The G400 can use mga, others can't, so they use the framebuffer
  393.       
  394.       # Output to the framebuffer where the TV is
  395.       $vodriver = "fbdev";
  396.       $options .= "-fb /dev/$fb ";
  397.       
  398.       # Expand to the framebuffer size so the video is in the middle
  399.       $vop .= ",expand=768:576";
  400.       
  401.       if ( ( $mhz > $fMHZ and $ENV{"ACCEL"} ne "no" ) or $ENV{"ACCEL"} eq "sw" ) {
  402.     # Scale to the PAL width and the appropriate height
  403.     $vop .= ",scale=720:-2";
  404.       }
  405.     }
  406.     
  407.     # The framebuffer has been already set up, don't change it later
  408.     $canChangeFB = 0;
  409.   } elsif( $videoCard eq "Ati" ) {
  410.     $vodriver = "vesa:vidix";
  411.   } else {
  412.     $vodriver = "vesa";
  413.   }
  414.  
  415.   # vesa can't change the framebuffer, other drivers sometimes can.
  416.   if ($vodriver eq "vesa") {
  417.     $canChangeFB = 0;
  418.   }
  419.  
  420.   ##################
  421.   ###  and now for the default case...
  422.   ##########################################
  423. } else {
  424.   #################
  425.   ##  Matrox 200/400/450/550 can take advantage
  426.   ##  of the special mga_vid driver!
  427.   #################
  428.   if ( $videoCard eq "Matrox" ){
  429.     system "modprobe -s matroxfb_base  >> $modLog 2>> $modErr";
  430.     system "modprobe -s mga_vid        >> $modLog 2>> $modErr";
  431. #    system "modprobe -s i2c-matroxfb   >> $modLog 2>> $modErr"; # only for TVout!
  432. #    system "modprobe -s matroxfb_maven >> $modLog 2>> $modErr"; # only for TVout!
  433.     if( -e "/dev/mga_vid" and -e "/dev/fb0" ){
  434.       $vodriver = "mga";
  435.       $options .= "-fs ";
  436.       ## Making sure the color depth is 32bpp...
  437.       system "fbset -depth 32 -xres 800 -yres 600";
  438.     } else {
  439.       $vodriver = "vesa:vidix";
  440.       $options .= "-zoom ";
  441.     }
  442.     #################
  443.     ##  Trident CyberBlade cards
  444.     #################
  445.   } elsif ( $videoCard eq "CyberBlade" ) {
  446.     system "modprobe -s fbgen";
  447.     my $kernelVersion = `uname -r`;
  448.     chop $kernelVersion;
  449.     system "insmod /lib/modules/$kernelVersion/kernel/drivers/video/epiafb.o.gz";
  450.     ### Taken from http://sourceforge.net/forum/forum.php?thread_id=756152&forum_id=221920
  451.     system "fbset -t 17762 152 32 27 1 64 3 -g 800 600 800 600 24 -hsync high -vsync high -a";
  452.     #################
  453.     ##  3Dfx Voodoo cards have a special mplayer driver!
  454.     #################
  455.   } elsif ( $videoCard eq "3Dfx" ) {
  456.     $vodriver   = "tdfxfb";
  457.     system "modprobe -s tdfxfb >> $modLog 2>> $modErr";
  458.     unless( -e "/dev/fb0" ){
  459.       system "echo \"No FrameBuffer device has been detected, the fbdev driver can't run without it :-(\"";
  460.       system "echo \"Please reboot and select a different driver\"";
  461.       system "echo \"(press F2 at the boot prompt for a complete list)\"";
  462.       reboot(5);
  463.     }
  464.     $xSize = 800;
  465.     $ySize = 600;
  466.     system "fbset -g $xSize $ySize $xSize $ySize 16";
  467.     #################
  468.     ##  DXR3/H+ cards have their special mplayer driver too!
  469.     #################
  470.   } elsif ( $videoCard eq "DXR3/H+" ) {
  471.     system "modprobe -s i2c-core                                     >> $modLog 2>> $modErre";
  472.     system "modprobe -s adv717x swap_redblue_pal=1 pixelport_16bit=0 >> $modLog 2>> $modErr";
  473.     system "modprobe -s bt865                                        >> $modLog 2>> $modErr";
  474.     system "modprobe -s em8300 bt865_ucode_timeout=1                 >> $modLog 2>> $modErr";
  475.     system "em8300setup";
  476.     $vodriver  = "dxr3:prebuf:sync:/dev/em8300_mv-0";
  477.     $aodriver  = "oss:/dev/em8300_ma-0";
  478.     $options  .= "-vc mpegpes ";
  479.     #################
  480.     ##  Unless you have a 3Dfx, a Matrox or a Dxr3/H+, you end up using the fbdev or vesa
  481.     ##  driver depending on the CPU speed and video card model
  482.     ##  with or without the "vidix" driver depending on the mplayer support for you card
  483.     #################
  484.   } else {
  485.     if( -e "/dev/fb0" and ( $mhz > $fMHZ or $videoCardLine =~ /Radeon|Mach64| Rage |G200|G400|G450|G550|CyberBlade/i ) ){
  486.       $vodriver = "fbdev";
  487.       $xSize    = getFBxSize();
  488.       $ySize    = getFBySize();
  489.       $options .= "-geometry 50%:50% ";
  490.       if( $videoCardLine =~ /Radeon|Mach64| Rage |G200|G400|G450|G550|CyberBlade/i and $ENV{"ACCEL"} !~ /sw|no/ ){
  491.     ### Warning: -fs w/fbdev driver crashes MPlayer if the video rez
  492.     ### is bigger than the screen rez.
  493.     ### But if we don't add "-fs" then the movie won't be resized anymore.
  494.     ### Someone should fix this bug eventually...
  495.     $vodriver .= ":vidix";
  496.     $options .= "-fs ";
  497.       } elsif( ( $mhz > $fMHZ and $ENV{"ACCEL"} ne "no" ) or $ENV{"ACCEL"} eq "sw" ) {
  498.     $vop .= ",expand=$xSize:$ySize";
  499.     $vop .= ",scale=$xSize:-2";
  500.       } else {
  501. #    $options .= "-framedrop ";
  502.     $options =~ s/ -framedrop / -hardframedrop /
  503.       if $mhz < $vfMHZ;
  504.       }
  505.       ### Unfortunately there are cards that do not support the vesaFB...
  506.     } else {
  507.       $vodriver = "vesa";
  508.       if( $videoCardLine =~ /Radeon|Mach64| Rage |G200|G400|G450|G550|CyberBlade/i and $ENV{"ACCEL"} !~ /sw|no/ ){
  509.     $vodriver .= ":vidix";
  510.     $options  .= "-fs -zoom ";
  511.       } elsif( ( $mhz > $fMHZ and $ENV{"ACCEL"} ne "no" ) or $ENV{"ACCEL"} eq "sw" ) {
  512.     $vop .= ",expand=800:600";
  513.     $vop .= ",scale=800:-2";
  514.       } else {
  515. #    $options .= "-framedrop ";
  516.     $options =~ s/ \-framedrop / \-hardframedrop /
  517.       if $mhz < $vfMHZ;
  518.     $options  .= "-fs -zoom ";
  519.       }
  520.     }
  521.   }
  522. }
  523. ###################
  524. ### Let the user override the automatic vo driver selection
  525. ###########
  526. $vodriver = $ENV{"VO_DRIVER"} if defined $ENV{"VO_DRIVER"};
  527.  
  528. ### If we're using 'vesa' then we can add the 'Aspect' functions
  529. ### to the MPlayer menu
  530. if( $vodriver =~ /^vesa/ ){
  531.   $menu = `cat /root/.mplayer/menu.conf`;
  532.   $menu .= "
  533. <cmdlist name=\"aspect\" title=\"Aspect\" ptr=\"<>\" >
  534.       <e name=\"Original\" ok=\"switch_ratio -1\"/>
  535.       <e name=\"4:3\" ok=\"switch_ratio 1.33333\"/>
  536.       <e name=\"16:9\" ok=\"switch_ratio 1.77778\"/>
  537.       <e name=\"Cinemascope\" ok=\"switch_ratio 2.35\"/>
  538. </cmdlist>
  539. ";
  540.   $menu =~ s/(<e name=\"Stop\" ok=\"quit\"\/>)/$1\n    <e name=\"Aspect ...\" ok=\"set_menu aspect\"\/>/;
  541.   open MENU, "> /root/.mplayer/menu.conf";
  542.   print MENU $menu;
  543.   close MENU;
  544. }
  545.  
  546. ################
  547. ### Adding CD cache option and other optimizations, from a suggestion by Jose' Fandinho
  548. #################
  549. `free` =~ /Mem:\s+\d+\s+\d+\s+(\d+)/;
  550. $cache = $1 > 12000 ? 8192 : 1024;
  551. $options .= "-cache $cache -autoq 6 ";
  552. $vop .= ",pp=lb:a";
  553. # interesting settings appeared on the MPlayer ML
  554. # on the other side, it seems video quality gets poorer with all this stuff!
  555. #$vop .= ",pp=hb:128:20:a/vb:128:20:a/dr:a/al:a/lb:a";
  556. ################
  557. ### Other sparse options:
  558. ### -double is needed to avoid subtitles blinking
  559. ### -idx forces the reconstruction of the index for broken avi files
  560. ### -menu activates the nice mplayer menu feature
  561. ### -nooverlapsub turns off an annoying new mplayer subtitles feature
  562. ###  [hw ones are available only for a few drivers]
  563. #################
  564. $options .= "-idx -menu -nooverlapsub ";
  565. ### -double crashes mplayer with some video card,
  566. ### so better to leave users add it in case is really necessary
  567. $options .= "-double "        unless $ENV{"LABEL"} eq "sdl";
  568. ## $options .= "-loop $loop "    if $loop =~ /^\d+$/;
  569. $options .= "-shuffle "       if $random eq "y";
  570. ### This is needed to avoid vesa to die when trying to use vesa:vidix together
  571. ### with the mpeg12 filter - many thanks to A.V.Kuznetsov for this hint!
  572. $options .= "-vc ffmpeg12, "      if $vodriver =~ /^vesa/;
  573.  
  574. ## Now we can add our vop options
  575. $options .= "-vop $vop ";
  576.  
  577. ###################
  578. ### Let the user add mplayer options at will
  579. ### WARNING: eventually we shoud check somehow that no new vop option
  580. ### is added or it will override our ones!
  581. ###########
  582. $options .= " $ENV{'MP_OPTIONS'} " if defined $ENV{'MP_OPTIONS'};
  583.  
  584. ###################
  585. ### Let's finally modify the options according to the .movixrc file
  586. ###########
  587. $options .= $RC{"extra-mplayer-options"}." " if exists $RC{"extra-mplayer-options"};
  588. if( exists $RC{"unwanted-mplayer-options"} ){
  589.   $RC{"unwanted-mplayer-options"} =~ s/\s+/ /g;
  590.   $RC{"unwanted-mplayer-options"} =~ s/^\s+//;
  591.   $RC{"unwanted-mplayer-options"} =~ s/\s+$//;
  592.   @options = split " ", $RC{"unwanted-mplayer-options"};
  593.   foreach $option (@options){
  594.     $options =~ s/$option / /;
  595.   }
  596. }
  597.  
  598. #######################################3
  599. ####  Playing all files in /cdrom...
  600. ##############
  601. $mplayer = "/usr/local/bin/mplayer";
  602. $mDir    = "/cdrom/";
  603. $log     = "/tmp/mplayer.log";
  604. $err     = "/tmp/mplayer.err";
  605.  
  606. ##################################################
  607. ### Playing the items in the list
  608. ##################################################
  609. $mplayerArgs  = "-vo $vodriver ";
  610. $mplayerArgs .= "-ao $aodriver " if $aodriver ne "";
  611. $mplayerArgs .= "$options ";
  612.  
  613. if ( -e "/tmp/movix.music.avi" ) {
  614.     $mplayerArgs .= "-bgvideo /tmp/movix.music.avi ";
  615. }
  616.  
  617. ######################################################
  618. ### Saving the options for the end of the playback
  619. ####################
  620. $mplayerOptions = $mplayerArgs;
  621.  
  622. ##################################################
  623. ### Creating the MPlayer play options depending
  624. ### whether we are trying to play an eMoviX CD
  625. ### or a ACD/VCD/DVD/MCD
  626. ###################
  627. $mplayerArgs .= mplayerPlayOption($scriptName);
  628.  
  629. # if we just wanted to get a playlist, we're done
  630. exit if $scriptName =~ /list/;
  631.  
  632. ### we want a log except for the "aa" case, because in
  633. ### that case only the movie is shown as STDIN of mplayer!!!
  634. $mplayerArgs .= " >> $log" unless $ENV{"LABEL"} eq "aa" or $scriptName eq "mcd";
  635. $mplayerArgs .= " 2>> $err";
  636. system "echo \"Running $mplayer $mplayerArgs\" >> $log";
  637. #################
  638. ## this is to avoid a blanking cursor that appears with some card under the vesa vo driver
  639. ###########################
  640. system "setterm -cursor off" unless $ENV{"LABEL"} eq "aa";
  641.  
  642. # Time to turn off the bootsplash
  643. system "echo verbose > /proc/splash";
  644.  
  645. #############
  646. ### Finally we can run mplayer!
  647. ##########################################
  648. my $i = $loop;
  649. while( $loop == 0 or $i-- > 0 ){
  650.   `echo "off" > /proc/splash`
  651.     if -e "/dev/fb/0" and `cat /proc/fb` =~ /VESA/;
  652.   system "clear ; $mplayer $mplayerArgs; echo \$? > /tmp/mplayer.exitcode";
  653.   `echo "on" > /proc/splash`
  654.     if -e "/dev/fb/0" and `cat /proc/fb` =~ /VESA/;
  655. }
  656.  
  657. ### Eject the CD if asked to
  658. #$getridof = $eject eq "y" ? "eject" : "umount";
  659. `ls -l /cdrom` =~ /cdrom(\d)/;
  660. $cdDev = "/dev/cdroms/cdrom$1";
  661. $cdDev = $1 if $mplayerArgs =~ /(?:-dvd-device|-cdrom-device) ([\S]+) /;
  662.  
  663. system "echo \"$getridof $cdDev\" >> $cdMntLog 2>> $cdMntErr";
  664. system "eject $cdDev" if $eject =~ /y/i;
  665.  
  666. clearInfoSub();
  667.  
  668. if( $shut eq "y" ){
  669.     system "echo \"The system will shut down in 5 seconds!\"";
  670.     for( my $i=0; $i < 5; $i++ ){
  671.     sleep(1);
  672.     system "echo -n \".\"";
  673.     }
  674.     system "poweroff";
  675. } elsif( $reboot eq "y" ) {
  676.     system "echo \"The system will reboot in 5 seconds!\"";
  677.     for( my $i=0; $i < 5; $i++ ){
  678.     sleep(1);
  679.     system "echo -n \".\"";
  680.     }
  681.     system "brc";
  682. } else {
  683.   # 166 is the "halt" exit code of mplayer
  684.   while(`cat /tmp/mplayer.exitcode` !~ /166/ ){
  685.     `clear`;
  686.     `echo "off" > /proc/splash`
  687.       if -e "/dev/fb/0" and `cat /proc/fb` =~ /VESA/;
  688.     
  689.     # With AsciiArt output, we can't really use the menu
  690.     last if $ENV{"LABEL"} eq "aa"; 
  691.     
  692.     # Start the menu again
  693.     `$mplayer $mplayerOptions -menu-disp /tmp/movix.music.avi -loop 0 \\
  694.               >> $log 2>> $err ; \\
  695.      echo \$? > /tmp/mplayer.exitcode`;
  696.     
  697.     `echo "on" > /proc/splash`
  698.       if -e "/dev/fb/0" and `cat /proc/fb` =~ /VESA/;
  699.   }
  700.   ##############
  701.   ## turning the cursor back on
  702.   ############
  703.   system "setterm -cursor on";
  704.  
  705.   print "\n\nEnd of the show...\n";
  706.   print "\nHave a nice day :-)\n";
  707. }
  708.  
  709. ###################################################
  710. #########################################
  711. ########################
  712. sub loadBootParm {
  713.   my @pairs = split " ", `cat /proc/cmdline`;
  714.   foreach my $pair (@pairs) {
  715.     next unless $pair =~ /^([^\=]+)\=(.+)$/;
  716.     $ENV{$1} = $2;
  717.   }
  718. }
  719.  
  720. sub readRCFile {
  721.   return unless -e "/root/.movixrc";
  722.   open RC, "/root/.movixrc";
  723.   while(<RC>){
  724.     next if /^\#/ or /^\s*$/;
  725.     next unless /^([^=]+)=(.+)$/;
  726.     $RC{$1}=$2;
  727.   }
  728.   close RC;
  729. }
  730.  
  731. sub reboot {
  732.     my $sec = shift;
  733.     $sec = 5 unless $sec =~ /^\d+$/;
  734.     system "echo \"The system will reboot in $sec seconds!\"";
  735.     for( my $i=0; $i < $sec; $i++ ){
  736.     sleep(1);
  737.     system "echo -n \".\"";
  738.     }
  739.     system "brc";
  740. }
  741.  
  742. sub getFBxSize {
  743.     my $xSize;
  744.     open FBINFO, "fbset |";
  745.     while(<FBINFO>){
  746. #        print "$_";
  747.         if( /^mode\s+\"(\d+)x\d+/ ){
  748.             $xSize = $1;
  749.             last;
  750.         }
  751.     }
  752.     close FBINFO;
  753.     return $xSize;
  754. }
  755.  
  756. sub getFBySize {
  757.     my $ySize;
  758.     open FBINFO, "fbset |";
  759.     while(<FBINFO>){
  760. #        print "$_";
  761.         if( /^mode\s+\"\d+x(\d+)/ ){
  762.             $ySize = $1;
  763.             last;
  764.         }
  765.     }
  766.     close FBINFO;
  767.     return $ySize;
  768. }
  769.  
  770. sub cdDetect {
  771.   my $sn = shift;
  772.   my $N  = shift;
  773.  
  774.   print "Looking for your cd...\n";
  775.   foreach my $cdDev (split " ", `ls /dev/cdroms/cdrom*`){
  776.     if( $sn eq "dvd" ){
  777.       my $n = $N > 0 ? $N : 1;
  778.       $id = `mplayer -identify -dvd-device $cdDev dvd://$n 2> /dev/null`;
  779.       if($id =~ /DVD successfully opened/){
  780.     print "DVD found in $cdDev!\n";
  781.     $dvd_device = $cdDev;
  782.     last;
  783.       }
  784.     } elsif( $sn eq "vcd" ) {
  785.       $id = `mplayer -identify -cdrom-device $cdDev vcd://$N 2> /dev/null`;
  786.       if($id =~ /MPEG-PS file format detected/){
  787.     print "VCD found in $cdDev!\n";
  788.     $cdrom_device = $cdDev;
  789.     last;
  790.       }
  791.     } elsif( $sn eq "acd" ) {
  792.       $id = `mplayer -identify -cdrom-device $cdDev cdda:// 2> /dev/null`;
  793.       if($id =~ /Found Audio CD/){
  794.     print "AudioCD found in $cdDev!\n";
  795.     $cdrom_device = $cdDev;
  796.     last;
  797.       }
  798.     } else {
  799.  
  800.       $cdDev =~ /cdrom(\d+)$/;
  801.       $i = $1;
  802.       next if defined $N and $N != $i;
  803.  
  804.       system "rm -f /cdrom ; ln -s /cdrom$i /cdrom";
  805.       #      $cdrom = "/cdrom$i";
  806.       $movixCheckFile = "/cdrom$i/isolinux/movix.lss";
  807.       #      system "cd /; umount /cdrom" if `grep cdrom /etc/mtab`;
  808.       #system "mount $cdDev /cdrom -t iso9660 >> $cdMntLog 2>> $cdMntErr";
  809.       if( -e $movixCheckFile and $sn ne "mcd" ){
  810.     print "Found eMoviX cd on $cdDev!\n";
  811.     ### Setting hw parameters of the CD device:
  812.     ### dma on, read-ahead set to 8 sectors (4k), irq unmasking on, mode set to udma2
  813.     system "hdparm -d1 -a8 -u1 -X34 $cdDev >> $cdMntLog 2>> $cdMntErr"
  814.       unless $dma =~ /^[nN]/;
  815.     ### Decreasing the CD-ROMs speed to reduce the noise unless negated at boot time
  816.     system "eject -x 12 $cdDev" unless $slow =~ /^[nN]/;
  817.     ### Copy the right set of fonts from the MoviX cd...
  818.     print "Setting up your fonts...\n";
  819.     `rm -f /tmp/subfont.ttf /tmp/font/* /root/.mplayer/subfont.ttf /root/.mplayer/font`;
  820.     if( -e "/cdrom/mplayer/font" ){
  821.       `cp -a /cdrom/mplayer/font/ /tmp/`;
  822.       `ln -s /tmp/font/  /root/.mplayer/`;
  823.     } else {
  824.       `cp -a /cdrom/mplayer/subfont.ttf /tmp/`;
  825.       `ln -s /tmp/subfont.ttf /root/.mplayer/`;
  826.     }
  827.     if( `ls /usr/local/mplayer/share/mplayer/font/*.gz 2>/dev/null` ){
  828.       # unpack fonts if they are gzipped
  829.       system "for gz in /usr/local/mplayer/share/mplayer/font/*.gz; do
  830.                   chmod 644 \$gz
  831.                   gunzip \$gz 2>/dev/null
  832.               done";
  833.     }
  834.  
  835.         #Search for audio files and create subtitles for them
  836.         getAudioFiles("/cdrom/");        
  837.  
  838.     last;
  839.       } else {
  840.     # No Movix system found - look for media files in the root dir of the CD
  841.     my @files;
  842.     foreach (("[aA][vV][iI]","[mM][oO][vV]","[mM][pP][gG]","[mM][pP][eE][gG]","[aA][sS][fF]","[wW][mM][vV]","[mM][pP]3","[oO][gG][gG]")){
  843.       push @files, `find /cdrom/ -name \"*.$_\"`;
  844.       last if @files > 0;
  845.     }
  846.     # No media files on the CD - unmount it
  847.     if (@files == 0) {
  848.       #system "umount /cdrom >> $cdMntLog 2>> $cdMntErr";
  849.     } else {
  850.       print "Found media files on $cdDev!\n";
  851.       `eject -x 12 $cdDev` unless $slow =~ /^[nN]/;
  852.  
  853.         #Search for audio files and create subtitles for them
  854.         getAudioFiles("/cdrom/");        
  855.  
  856.       last;
  857.     }
  858.       }
  859.     }
  860.   }
  861.   closedir(CD);
  862.   if( !-e $movixCheckFile and @files == 0 and $dvd_device eq "" and $cdrom-device eq "" ){
  863.     print "Could not find your eMoviX-CD/ACD/VCD/DVD!\nMaybe you are using a USB cd or something stranger:\nunfortunately MoviX until now supports only IDE or SCSI drives, but of course it would be very nice if you'd write a patch and send it to the author that would happily add it to next release :-)\n";
  864.   }
  865. }
  866.  
  867. sub mplayerPlayOption {
  868.   my $sn = shift;
  869.   my @audioTracks;
  870.   my %audioTracks;
  871.   my $at;
  872.   my @subsTracks;
  873.   my %subsTracks;
  874.   my $st;
  875.   my $title;
  876.  
  877.   if( $sn eq "dvd" ){
  878.     my $dvd_opts = "-dvd-device $dvd_device ";
  879.     ### if no track no has been given, play the longest track
  880.     if( ! ($N > 0 ) ){ 
  881.       @tracks = split "\n", `lsdvd $dvd_device 2> /dev/null`;
  882.       $N = 0;
  883.       $l1 = 0;
  884.       foreach (@tracks){
  885.     /Title\: 0?(\d+), Length\: (\d+)\:(\d+)\:(\d+)/;
  886.     $l2 = $2*3600+$3*60+$4;
  887.     if( $l2 > $l1 ){
  888.       $N = $1;
  889.       $l1 = $l2;
  890.     }
  891.       }
  892.     }
  893.     
  894.     foreach my $line (split "\n", `lsdvd -a -s -t $N $dvd_device 2> /dev/null` ){
  895.       $line =~ s/^\s*//;
  896.       $title = $1 if $line =~ /^Disc Title\: (.+)$/;
  897.       push @audioTracks, $line if $line =~ /^Audio/;
  898.       push @subsTracks,  $line if $line =~ /^Subti/;
  899.     }      
  900.  
  901.     print "\nDisc Title: $title" unless $title =~ /^\s*$/;
  902.  
  903.     unless (@audioTracks == 1){
  904.       print "\nThere are multiple audio tracks on this DVD:\n\n";
  905.       foreach (@audioTracks){
  906.     /Audio\: 0?(\d+), Language\: (\w+) /;
  907.     $audioTracks{$1} = $2;
  908.     print "$_\n";
  909.       }
  910.       print "\nSelect the one you want and press ENTER: ";
  911.       $at = <STDIN>;
  912.       chop $at;
  913.     }
  914.     $dvd_opts .= "-alang $audioTracks{$at} " if defined $audioTracks{$at};
  915.  
  916.     unless (@subsTracks == 0){
  917.       print "\nYou can choose among the following subtitles sets:\n\n";
  918.       foreach (@subsTracks){
  919.     /Subtitle\: 0?(\d+), Language\: (\w+) /;
  920.     print "$_\n";
  921.     $subsTracks{$1} = $2;
  922.       }
  923.       print "\nSelect the subtitles you want and press ENTER (0 = no subtitles): ";
  924.       $st = <STDIN>;
  925.       chop $st;
  926.     }
  927.     $dvd_opts .= "-slang $subsTracks{$st} " if defined $subsTracks{$st};
  928.  
  929.     `eject -x 12 $dvd_device` unless $slow =~ /^[nN]/;
  930.     
  931.     $dvd_opts .= " dvd://$N ";
  932.     return $dvd_opts;
  933.   } elsif ($sn eq "vcd" ){
  934.     `eject -x 12 $cdrom_device` unless $slow =~ /^[nN]/;
  935.     return "-cdrom-device $cdrom_device vcd://$N ";
  936.   } elsif ($sn eq "acd" ){
  937.     `eject -x 12 $cdrom_device` unless $slow =~ /^[nN]/;
  938.     return "-cdrom-device $cdrom_device cdda:// ";
  939.   } elsif ($sn eq "mcd" ){
  940.     # mp3 cd patch from Jochen Puchalla <mail@puchalla-online.de>
  941.     system "find $mDir -name '*.mp3' > /tmp/playlist";
  942.     system "find $mDir -name '*.MP3' >> /tmp/playlist";
  943.     system "find $mDir -name '*.ogg' >> /tmp/playlist";
  944.     system "find $mDir -name '*.OGG' >> /tmp/playlist";
  945.     system "find $mDir -name '*.wav' >> /tmp/playlist";
  946.     system "find $mDir -name '*.WAV' >> /tmp/playlist";
  947.     system "sort /tmp/playlist > /movix.list";
  948.     return "-playlist /movix.list ";
  949.   } else {
  950.     ##################################################
  951.     ### Creating the list of all files to play
  952.     ### in case no default list [i.e. named movix.*] is found
  953.     ##################
  954.     $playlist = undef;
  955.     if( defined $ENV{"LIST"} and -e "$mDir$ENV{LIST}" ){
  956.       $playlist = $mDir.$ENV{"LIST"};
  957.     } elsif( -e "$mDir/movix.asx" ){
  958.       $playlist = "$mDir/movix.asx";
  959.     } elsif ( -e "$mDir/movix.txt" ) {
  960.       $playlist = "$mDir/movix.txt";
  961.     } elsif ( -e "$mDir/movix.list" ) {
  962.       $playlist = "$mDir/movix.list";
  963.     } elsif ( -e "$mDir/movix.m3u" ) {
  964.       $playlist = "$mDir/movix.m3u";
  965.     }
  966.     if( ! defined $playlist ) {
  967.       my @files;
  968.       foreach (("[aA][vV][iI]","[mM][pP][gG]","[mM][oO][vV]","[mM][pP][eE][gG]","[aA][sS][fF]","[wW][mM][vV]","[mM][pP]3","[oO][gG][gG]","[oO][gG][mM]")){
  969.     push @files, split "\n", `find /cdrom/ -name \"*.$_\"`;
  970.       }
  971.       my $list = "";
  972.       foreach (sort @files){
  973.     $list .= "$_\n"
  974.       unless /movix.music.avi/;
  975.       }
  976.       `echo \"$list\" > /movix.list`;
  977.       $playlist = "/movix.list";
  978.     }
  979.     return "-playlist $playlist ";
  980.   }
  981. }
  982.  
  983. # Create subtitles for audio files
  984. sub createInfoSub {
  985.   my $file = shift;
  986. #  chop $file;
  987.   $file =~ /\/([^\/]+)\.(mp3|ogg|wav)$/i;
  988.   #print STDERR "++++++++++  file = $file, r = $1\n";
  989.   open INFO, "> /root/.mplayer/sub/$1.sub";
  990.   print INFO "[SUBTITLE]\n00:00:00.00,10:00:00.00\n";
  991.   print INFO "File: $file [br] [br]";
  992.  
  993.   my $getInfoCmd = mediaInfoProg($file);
  994.   my $i=0;
  995.   foreach ( split "\n", `$getInfoCmd` ){
  996.     print INFO "Title: $3"."[br]"           and $i++ if /^\s+([Tt]itle(: |=)(.+))$/;
  997.     print INFO "Artist: $3"."[br]"          and $i++ if /^\s+([Aa]rtist(: |=)(.+))$/;
  998.     print INFO "Album: $3"."[br]"           and $i++ if /^\s+([Aa]lbum(: |=)(.+))$/;
  999.     print INFO "Playback length: $3"."[br]" and $i++ if /^\s+(Playback length(: |=)(.+))$/;
  1000.     print INFO "Date: $3"."[br]"            and $i++ if /^\s+((Year: |date=)(.+))$/;
  1001.     print INFO "Genre: $3"."[br]"           and $i++ if /^\s+([Gg]enre(: |=)(.+))$/;
  1002.   }
  1003.   print INFO " [br]" if $i > 0;
  1004.   print INFO "\n";
  1005.   close INFO;
  1006. }
  1007.  
  1008. # Delete auto-created subtitles
  1009. sub clearInfoSub {
  1010.   `rm -f /root/.mplayer/sub/*.sub`;
  1011. }
  1012.  
  1013. # Decides on the right command for getting info on media files
  1014. sub mediaInfoProg {
  1015.     my $file = shift;
  1016.     
  1017.     if ( $file =~ /\.ogg$/i ) {
  1018.         return("/usr/bin/ogginfo \"$file\"");
  1019.     } else {
  1020.         return("/usr/bin/mplayer -identify \"$file\" 2>/dev/null");
  1021.     }
  1022. }
  1023.  
  1024. # Stolen from movix 0.8.1pre3 movix.pl - go over the list of files and
  1025. # create info files for them
  1026. sub getAudioFiles {
  1027.   my $partition = shift;
  1028.   #print STDERR "partition = $partition\n";
  1029.   my @list;
  1030.   my $mntPoint = $partition;
  1031.  
  1032.   push @list, `find \"$mntPoint\" -name \"*.[mM][pP]3\"`;
  1033.   push @list, `find \"$mntPoint\" -name \"*.[oO][gG][gG]\"`;
  1034.   push @list, `find \"$mntPoint\" -name \"*.[wW][aA][vV]\"`;
  1035.  
  1036.   foreach (@list){
  1037.     s/^\s*//;
  1038.     chop;
  1039.     createInfoSub($_);
  1040.   }
  1041.   return sort @list;
  1042. }
  1043.